//
//  KZUserCenterHeaderView.m
//  lg_zhinengbeikao_english
//
//  Created by 朱凯 on 2018/12/17.
//  Copyright © 2018年 zhukai. All rights reserved.
//

#import "KZUserCenterHeaderView.h"

@implementation KZUserCenterHeaderView
{
    UIImageView *_bgView;   // 背景
    UIImageView *_iconView; // 头像
    UILabel *_nickLabel;    // 昵称
    UILabel *_accountLabel; // 账号
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
#pragma mark - 创建视图
- (void)setupUI {
    
    _bgView = [UIImageView new];
    _bgView.image = [UIImage imageWithColor:kBlueColor];
    [self addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    _iconView = [UIImageView new];
    _iconView.layer.cornerRadius = H(40);
    _iconView.layer.masksToBounds = true;
    _iconView.image = [UIImage imageWithColor:kRedColor];
    [self addSubview:_iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(H(80));
        make.left.mas_equalTo(W(15));
        make.centerY.equalTo(self).offset(H(15));
    }];
    
    _nickLabel = [[UILabel alloc] init];
    _nickLabel.text = @"奥黛丽赫本（学生）";
    _nickLabel.font = FONT(14);
    _nickLabel.textAlignment = NSTextAlignmentLeft;
    _nickLabel.textColor = [UIColor whiteColor];
    [self addSubview:_nickLabel];
    [_nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_iconView.mas_right).offset(W(15));
        make.bottom.equalTo(self->_iconView.mas_centerY).offset(H(-3));
    }];
    _nickLabel.attributedText = [_nickLabel.text attributeStringWithAttributes:@{NSFontAttributeName: FONT(20)} scope:@"奥黛丽赫本"];
    
    _accountLabel = [[UILabel alloc] init];
    _accountLabel.text = @"账号：sa0000001";
    _accountLabel.font = FONT(15);
    _accountLabel.textAlignment = NSTextAlignmentLeft;
    _accountLabel.textColor = [UIColor whiteColor];
    [self addSubview:_accountLabel];
    [_accountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_nickLabel);
        make.top.equalTo(self->_iconView.mas_centerY).offset(H(3));
    }];
}

#pragma mark - setter
- (void)setOffset:(CGFloat)offset {
    
    _offset = offset;
    NSLog(@"%lf", _offset);
    [_bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(offset);
    }];
}

@end
